/**
 * @Project： Lqyd_Android
 * @Title：BookShelfPage
 * @Description：
 * @Author：wayne
 * @Date：2014年8月11日上午10:40:42
 */
package com.shwread.android.qysw.activity;

import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;

import com.NewActionHelp;
import com.TrainActionHelp;
import com.shwread.android.ui.page.BookShelfPage;
import com.shwread.android.ui.page.BoutiquePage;
import com.tgx.tina.android.ipc.framework.IUIPage;

import logic.constants.Const;

/**
 * 书架页面
 */
public class BookShelfActivity extends MainActivity {

    /**
     * 是否是离线阅读
     */
    public static boolean OFFINE_READ = false;
    private Handler myhandler = new Handler() {

        @Override
        public void handleMessage(Message msg) {
            if (curPage != null) {
                curPage.notifyView(msg.what, msg.getData());
            }
        }

    };

    @Override
    public Handler getUIHandler() {
        return myhandler;
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        changePage(new BookShelfPage(this), IUIPage.KEEP_LAST_STATUS);
    }

    @Override
    protected void onResume() {
        super.onResume();
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        OFFINE_READ = false;
    }

    @Override
    public void onBackPressed() {
        if (OFFINE_READ) {
            //如果是离线阅读进入的个人书架,则返回到登录界面
            toLoginActivity();
            return;
        }
        BoutiquePage.fromBoutique = false;
        if (curPage != null && curPage.handleBack()) {
            return;
        }
        if (history.isEmpty()) {
            finish();
        }
        onBackPressed0();
    }

    public void toLoginActivity() {//去登录界面
        Const.phone_number = "";
        Const.login_key = "";
        NewActionHelp.setLoginKey("");
        NewActionHelp.setAccount("");
        TrainActionHelp.setLoginKey("");
        TrainActionHelp.setAccount("");
        Intent intent = new Intent(this, NewLoginActivity.class);
        startActivity(intent);
        finish();
    }
}
